using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data.SqlClient;
using System.Data;
using PointOfSale.Global; 
//<added by me> 
using CrystalDecisions.Shared; 
using CrystalDecisions.CrystalReports.Engine; 
//</added by me> 
namespace PointOfSale.Report.Purchase 
{ 
	/// <summary> 
	/// Summary description for Form1. 
	/// </summary> 
	public class frmPurchaseList : System.Windows.Forms.Form 
	{ 
		// <Added by me> 
		
		public DateTime dFromDate = new DateTime();
		public DateTime dToDate = new DateTime();	

		//private CrystalReport1 crReportDocument = new 	CrystalReport1 (); 
		private Database crDatabase; 
		private Tables crTables; 
		private Table crTable; 
		private TableLogOnInfo crTableLogOnInfo; 
		private ConnectionInfo crConnectionInfo = new 	ConnectionInfo (); 


		string report_file = ""; 
		//public static frmReportSoCTTM clsfrmReport;
		ReportDocument crReportDocument = new ReportDocument();
		private CrystalDecisions.Windows.Forms.CrystalReportViewer crpViewer; 
		/// <summary> 
		/// Required designer variable. 
		/// </summary> 
		private System.ComponentModel.Container components = null; 

		public frmPurchaseList() 
		{ 
			// 
			// Required for Windows Form Designer support 
			// 
			InitializeComponent(); 

			// 
			// TODO: Add any constructor code after InitializeComponent call 
			// 
		} 

		/// <summary> 
		/// Clean up any resources being used. 
		/// </summary> 
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if (components != null) 
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 

#region Windows Form Designer generated code 
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor. 
		/// </summary> 
		private void InitializeComponent() 
		{ 
			this.crpViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			this.SuspendLayout();
			// 
			// crpViewer
			// 
			this.crpViewer.ActiveViewIndex = -1;
			this.crpViewer.DisplayGroupTree = false;
			this.crpViewer.Dock = System.Windows.Forms.DockStyle.Fill;
			this.crpViewer.Location = new System.Drawing.Point(0, 0);
			this.crpViewer.Name = "crpViewer";
			this.crpViewer.ReportSource = null;
			this.crpViewer.ShowGroupTreeButton = false;
			this.crpViewer.Size = new System.Drawing.Size(712, 381);
			this.crpViewer.TabIndex = 0;
			// 
			// frmPurchaseList
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(712, 381);
			this.Controls.Add(this.crpViewer);
			this.Name = "frmPurchaseList";
			this.Text = "Purchase Item List";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.Reporte_Load);
			this.ResumeLayout(false);

		} 
#endregion 


		private void makeReport(string ReportFile) 
		{ 

			crReportDocument.Load(ReportFile); 
			crpViewer.ReportSource = crReportDocument; 

		} 

		
 
		private ParameterValues AddDiscreteValue (string paramValue, ParameterValues paramValues)
		{
			ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue ();
			paramDiscreteValue.Value = paramValues.Add (paramDiscreteValue);
			return paramValues;
		}
		private void SetParamValue	(string paramName, string paramValue)
		{

			crReportDocument.SetParameterValue(paramName,paramValue);

		}

		private string GetParamValue	(string paramName)
		{
			string tmpValue="";
			for(int i=0;i<crReportDocument.DataDefinition.FormulaFields.Count;  i++)
			{
				if(crReportDocument.DataDefinition.FormulaFields[i].FormulaName=="{" + paramName +  "}")
					tmpValue= crReportDocument.DataDefinition.FormulaFields[i].Text ;
			}
			return tmpValue;
		}

		private DataColumn CreateNewColumn( string sColumnType, string sColumnCaption,string sColumnName)
		{
			DataColumn dtColumn = new DataColumn();			
			dtColumn.DataType = System.Type.GetType("System." + sColumnType);
			dtColumn.ColumnName = sColumnName;
			dtColumn.Caption = sColumnCaption;			
			dtColumn.AutoIncrement = false;			
			dtColumn.ReadOnly = false;
			dtColumn.Unique = false;
			return dtColumn;
		}

		private void Reporte_Load(object sender, System.EventArgs e)
		{
			
			try
			{
				
				dsPOSPurchaseList ds = new dsPOSPurchaseList();
				SqlCommand salesCMD = new SqlCommand("spPOSPurchaseList",clsGlobal.g_DataConn);
				SqlCommand TotalCMD = new SqlCommand("spPOSPurchaseListTotal", clsGlobal.g_DataConn);
				salesCMD.CommandType = CommandType.StoredProcedure;
				TotalCMD.CommandType = CommandType.StoredProcedure;

				SqlParameter myParmFromDate = salesCMD.Parameters.Add("@FromDate", SqlDbType.DateTime);
				SqlParameter myParmToDate = salesCMD.Parameters.Add("@ToDate", SqlDbType.DateTime);
				
	
				myParmFromDate.Value = dFromDate.ToShortDateString().ToString();
				myParmToDate.Value = dToDate.ToShortDateString().ToString();
				
		
				myParmFromDate.Direction=ParameterDirection.Input;
				myParmToDate.Direction=ParameterDirection.Input;
				

				SqlParameter ParmFromDate = TotalCMD.Parameters.Add("@FromDate", SqlDbType.DateTime);
				SqlParameter ParmToDate = TotalCMD.Parameters.Add("@ToDate", SqlDbType.DateTime);
				
	
				ParmFromDate.Value = dFromDate.ToShortDateString().ToString();
				ParmToDate.Value = dToDate.ToShortDateString().ToString();
				
		
				ParmFromDate.Direction=ParameterDirection.Input;
				ParmToDate.Direction=ParameterDirection.Input;
				

				System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(TotalCMD);
				sda.Fill(ds, "spPOSPurchaseListTotal");
				sda = new System.Data.SqlClient.SqlDataAdapter(salesCMD);
				sda.Fill(ds, "spPOSPurchaseList");			
				
				rptPurchaseList rpt = new rptPurchaseList();
				rpt.SetDataSource(ds);
				rpt.SetParameterValue("@FromDate",dFromDate.ToShortDateString().ToString());
				rpt.SetParameterValue("@ToDate",dToDate.ToShortDateString().ToString());
				this.crpViewer.ReportSource = rpt;
		
				
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}

		
		}
	} 
} 